/**
 * 路由配置
 */
import React from 'react';
import { createBrowserRouter, Navigate } from 'react-router-dom';
import MainLayout from '@/layouts/MainLayout';
import Login from '@/modules/user/Login';
import ProtectedRoute from './components/ProtectedRoute';

// 懒加载页面组件
const Dashboard = React.lazy(() => import('@/modules/dashboard/Dashboard'));

// 商品管理
const ProductList = React.lazy(() => import('@/modules/product/ProductList'));
const ProductCategory = React.lazy(() => import('@/modules/product/ProductCategory'));
const ProductUpload = React.lazy(() => import('@/modules/product/ProductUpload'));

// 订单管理
const OrderList = React.lazy(() => import('@/modules/order/OrderList'));
const OrderRefund = React.lazy(() => import('@/modules/order/OrderRefund'));

// 用户管理
const UserList = React.lazy(() => import('@/modules/user/UserList'));

// 协同文档
const DocumentList = React.lazy(() => import('@/modules/document/DocumentList'));
const DocumentCollab = React.lazy(() => import('@/modules/document/DocumentCollab'));
const TemplateManage = React.lazy(() => import('@/modules/document/TemplateManage'));

// 数据统计
const SalesStats = React.lazy(() => import('@/modules/statistics/SalesStats'));
const DataExport = React.lazy(() => import('@/modules/statistics/DataExport'));

// 文件管理
const FileManager = React.lazy(() => import('@/modules/file/FileManager'));
const Favorites = React.lazy(() => import('@/modules/file/Favorites'));
const RecycleBin = React.lazy(() => import('@/modules/file/RecycleBin'));
const SharePage = React.lazy(() => import('@/modules/file/SharePage'));

// 系统管理
const RoleManage = React.lazy(() => import('@/modules/system/RoleManage'));
const PermissionManage = React.lazy(() => import('@/modules/system/PermissionManage'));
const MenuManage = React.lazy(() => import('@/modules/system/MenuManage'));

// 即时通讯
const ChatCenter = React.lazy(() => import('@/modules/chat/ChatCenter'));

// 系统设置
const SystemSettings = React.lazy(() => import('@/modules/settings/SystemSettings'));

// 审计日志
const AuditLog = React.lazy(() => import('@/modules/audit/AuditLog'));

// 路由配置
const router = createBrowserRouter([
  // 分享页面（独立页面，不使用布局）
  {
    path: '/share/:shareCode',
    element: <SharePage />
  },
  {
      path: '/login',
      element: <Login />
    },
    // 受保护的主布局路由
    {
      path: '/',
      element: <ProtectedRoute />,
      children: [
        {
          element: <MainLayout />,
          children: [
      // 默认重定向到数据看板
      {
        index: true,
        element: <Navigate to="/dashboard" replace />
      },
      // 数据看板
      {
        path: 'dashboard',
        element: <Dashboard />
      },
      // 商品管理
      {
        path: 'product-list',
        element: <ProductList />
      },
      {
        path: 'product-category',
        element: <ProductCategory />
      },
      {
        path: 'product-upload',
        element: <ProductUpload />
      },
      // 订单管理
      {
        path: 'order-list',
        element: <OrderList />
      },
      {
        path: 'order-refund',
        element: <OrderRefund />
      },
      // 用户管理
      {
        path: 'user',
        element: <UserList />
      },
      // 协同文档
      {
        path: 'doc-list',
        element: <DocumentList />
      },
      {
        path: 'doc-collab',
        element: <DocumentCollab />
      },
      {
        path: 'doc-templates',
        element: <TemplateManage />
      },
      // 数据统计
      {
        path: 'sales-stats',
        element: <SalesStats />
      },
      {
        path: 'data-export',
        element: <DataExport />
      },
      // 文件管理
      {
        path: 'file-manage',
        element: <FileManager />
      },
      // 我的收藏
      {
        path: 'favorites',
        element: <Favorites />
      },
      // 回收站
      {
        path: 'recycle-bin',
        element: <RecycleBin />
      },
      // 系统管理
      {
        path: 'role-manage',
        element: <RoleManage />
      },
      {
        path: 'permission-manage',
        element: <PermissionManage />
      },
      {
        path: 'menu-manage',
        element: <MenuManage />
      },
      // 系统设置
      {
        path: 'settings',
        element: <SystemSettings />
      },
      // 审计日志
      {
        path: 'audit-log',
        element: <AuditLog />
      },
      {
        path: 'chat',
        element: <ChatCenter />
      }
        ]
      }
    ]
  },
  // 未匹配的路由重定向到登录页
  {
      path: '*',
      element: <Navigate to="/login" replace />
    },
  ]);

export default router;
